package com.yn.xgame.message;

import com.yn.xgame.IFunc2;
import com.yn.xgame.IServer;

import java.util.function.Function;

/**
 * SupplyAndConsumeMessage1
 * Created by wangboo on 17/7/13.
 */
public class SupplyAndConsumeMessage1<T, R> implements IFuncMessage {

    private T t;
    private Function<T, R> func;
    private IFunc2<T, R> consumer;
    private IServer consumeServer;

    public SupplyAndConsumeMessage1(IServer consumeServer, T t, Function<T, R> func, IFunc2<T, R> consumer) {
        this.t = t;
        this.consumeServer = consumeServer;
        this.func = func;
        this.consumer = consumer;
    }

    @Override
    public void apply() {
        R r = func.apply(t);
        Func2Message<T, R> func = new Func2Message<>(t, r, consumer);
        consumeServer.pushMessage(func);
    }

}
